/**
 * Create in 2012-7-29.
 */
package kit4j.tests.jdk.swing.dnd.table;

import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 * 
 * @author MiniKnife
 *
 */
public class DndModelTableCellRenderer extends DefaultTableCellRenderer {
	
	private static final long serialVersionUID = 1L;

//	private static final Logger log = LoggerFactory.getLogger(DndTableCellRenderer.class);

	/**
	 * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
	 */
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row,
			int column) {
		if(value instanceof DndTableModel) {
			DndTableModel<?> model = (DndTableModel<?>) value;
			Component comp = model.getModelRendererComponent();
			
			if(isSelected) {
				comp.setForeground(table.getForeground());
				comp.setBackground(table.getBackground());
			}
			
			return comp;
		} else {
			return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
		}
	}

}
